#ifndef _CEGuiD3D10BaseApplication_h_
#define _CEGuiD3D10BaseApplication_h_


#include "CEGuiBaseApplication.h"
#include "CEGUIGeometryBuffer.h"
#include "BVD3D10Renderer.h"
#include <D3DX10math.h>


#if defined( __WIN32__ ) || defined( _WIN32 )
#   define WIN32_LEAN_AND_MEAN
#   define NOMINMAX
#   include <windows.h>
#endif

// MSVC auto-linking
#if defined(_MSC_VER)
#   pragma comment(lib, "d3d10.lib")
#   if defined(_DEBUG)
#       if defined(CEGUI_STATIC)
#           pragma comment(lib, "CEGUIDirect3D10Renderer_Static_d.lib")
#       else
#           pragma comment(lib, "CEGUIDirect3D10Renderer_d.lib")
#       endif
#   else
#       if defined(CEGUI_STATIC)
#           pragma comment(lib, "CEGUIDirect3D10Renderer_Static.lib")
#       else
#           pragma comment(lib, "CEGUIDirect3D10Renderer.lib")
#       endif
#   endif
#endif

// forward declare struct that will hold D3D10 specifics

//TODO: The following include can be well designed (implemented in the cpp file)
#include "RendererModules/Direct3D10/CEGUIDirect3D10Renderer.h"
#include "Win32AppHelper.h"
#include "BvCamera.h"

struct CEGuiBaseApplicationImpl
{
    HWND d_window;
    IDXGISwapChain* d_swapChain;
    ID3D10Device* d_device;
    CEGUI::Direct3D10Renderer* d_renderer;
    Win32AppHelper::DirectInputState d_directInput;
};

//! CEGuiBaseApplication implementation for Microsoft Direct3D 10
class CEGuiD3D10BaseApplication : public CEGuiBaseApplication
{
    HRESULT createDeviceAndSwapChain();

    HRESULT createBackAndDepthBuffers();

public:
    //!Constructor.
    CEGuiD3D10BaseApplication();

    //! Destructor.
    ~CEGuiD3D10BaseApplication();

    // Implementation of base class abstract methods.
    void setup();
    bool execute(CEGuiSample* sampleApp);
    void cleanup();

protected:
    /*************************************************************************
        Implementation Methods
    *************************************************************************/
    // Initializes Direct3D system.
    HRESULT initD3DDevice();

    //! cleanup D3D objects / interfaces
    void cleanupDirect3D();

    void doFPSUpdate(void);

    bool overlayHandler(const CEGUI::EventArgs& args);

    /*************************************************************************
        Data fields
    *************************************************************************/
    //! Pointer to the struct holding D3D specific fields.
    CEGuiBaseApplicationImpl* pimpl;;

    // counter used to track elapsed time (for time pulse injection)
    DWORD d_lastFrameTime;
    // FPS stuff
    DWORD d_fps_lastTime;
    int d_fps_frames;
    int d_fps_value;
    char d_fps_textbuff[16];
    CEGUI::GeometryBuffer* d_fps_geometry;
    CEGUI::GeometryBuffer* d_logo_geometry;

    ID3D10Texture2D *backBuffer;
    ID3D10Texture2D *depthBuffer;
    ID3D10RenderTargetView *backBufferRTV;
    ID3D10DepthStencilView *depthBufferDSV;
    TextureId backBufferTexture;

    DXGI_FORMAT backBufferFormat;
    DXGI_FORMAT depthBufferFormat;
    int msaaSamples;

    
    /*************************************************************************
        custom fields: fudo
    *************************************************************************/
    //functions
    //virtual void drawPerFrame();

    //virtual HRESULT createScene();

    //virtual void createCamera();

    void createWindow();
    
    void createD3DDevice();

public:
    //variables
    //BvD3D10Renderer* bvRenderer;
    ID3D10Device* getD3DDevice() {return pimpl->d_device;};
    
};

#endif  // end of guard _CEGuiD3D10BaseApplication_h_
